﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.SessionState;
using FmcWebsite.Core;

namespace FmcWebsite.Web
{
    public class WebCategory
    {
        private Category category;
        private HttpSessionState session;

        private WebCategory(Category category, HttpSessionState session)
        {
            this.session = session;
            this.category = category;
        }

        public Category Category
        {
            get { return category; }
        }

        public string Name
        {
            get { return category.Name; }
        }

        public IEnumerable<WebCategory> Children
        {
            get
            {
                foreach (Category cat in category.Children)
                    yield return new WebCategory(cat, session);
            }
        }

        public WebCategory Parent
        {
            get
            {
                if (category.Parent != null)
                    return new WebCategory(category.Parent, session);
                return null;
            }
        }

        public HttpSessionState Session
        {
            get { return session; }
        }

        static public WebCategory ByCode(string category_code, HttpSessionState session)
        {
            return new WebCategory(Category.ByCode(category_code), session);
        }
    }
}
